<?php
/**
 * Desc: 存储室类
 * User: lisgroup
 * Date: 2018/5/14
 */

namespace App\Utility;


class Storeroom
{
    private static $instance;

    /**
     * 存储对象
     * @var array
     */
    private $items = [];

    public static function instance($name = '')
    {
        if (!isset(self::$instance)) self::$instance = new self();
        if ($name === '')
            return self::$instance;
        else
            return self::$instance->item($name);
    }

    public function item($name, $value = null)
    {
        $hashName = md5($name);
        $itemIns = isset($this->items[$hashName]) ? $this->items[$hashName] : null;

        if ($value !== null) {
            $this->items[$hashName] = $value;
            return true;
        } else {
            return $itemIns;
        }
    }
}